package xy.come.juhenews.Fragment;

import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;

import java.util.ArrayList;

import butterknife.BindView;
import lnjh.com.xcoordinatortablibrary.CoordinatorTabLayout;
import xy.come.juhenews.Adapter.MyPagerAdapter;
import xy.come.juhenews.Base.BaseFragment;
import xy.come.juhenews.MainActivity;
import xy.come.juhenews.R;

/**
 * Created by Xia_焱 on 2018/7/11.
 * e-mail：XiahaotianV@163.com
 */

public class HomeFragment extends BaseFragment {
    @BindView(R.id.vp_view)
    ViewPager mViewPager;
    @BindView(R.id.ctl_top)
    CoordinatorTabLayout mCoordinatorTabLayout;
    private int[] mImageArray, mColorArray;
    private ArrayList<Fragment> mFragments;
    //先实现出效果之后 第二版再进行升级
    private final String[] mTitles = {"头条", "国内", "体育", "军事", "科技", "时尚"};
    private final String[] mTitlesX = {"top", "guonei", "tiyu", "junshi", "keji", "shishang"};


    @Override
    protected int getLayoutResource() {
        return R.layout.fragment_home;
    }

    @Override
    public void initData() {

    }

    @Override
    protected void initView() {
        initFragments();
        initViewPager();
        mImageArray = new int[]{
                R.mipmap.icon_bg_top,
                R.mipmap.iocn_bg_gn,
                R.mipmap.icon_bg_run,
                R.mipmap.icon_bg_js,
                R.mipmap.bg_other,
                R.mipmap.icon_bg_ss};
        mColorArray = new int[]{
                android.R.color.holo_blue_light,
                android.R.color.holo_red_light,
                android.R.color.holo_green_light,
                android.R.color.holo_red_light,
                android.R.color.holo_blue_light,
                android.R.color.holo_green_light,};
        mCoordinatorTabLayout.TabSelectX(getActivity());
        mCoordinatorTabLayout
                .setTitle("口袋新闻")
                .setBackEnable(false).
                setTranslucentNavigationBar(getActivity())
                .setImageArray(mImageArray, mColorArray)
                .setupWithViewPager(mViewPager);


    }


    private void initFragments() {
        mFragments = new ArrayList<>();
        for (int i = 0; i < mTitles.length; i++) {
            NewsFragment newsFragment = new NewsFragment();
            newsFragment.setTitle(mTitlesX[i]);
            mFragments.add(newsFragment);
        }


    }

    private void initViewPager() {
        mViewPager.setAdapter(new MyPagerAdapter(getChildFragmentManager(), mFragments, mTitles));
        mViewPager.setCurrentItem(0);

    }


    @Override
    protected void lazyLoad() {
    }

}
